package com.digdes.calendar.service.impl;

import com.digdes.calendar.dao.UserDAO;
import com.digdes.calendar.gwt.client.dto.UserDTOImpl;
import com.digdes.calendar.model.User;
import com.digdes.calendar.service.UserService;

import java.util.HashSet;
import java.util.Set;

public class UserServiceImpl implements UserService {
    private UserDAO userDAO;


    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }


    public void saveUser(User user) {
        userDAO.saveUser(user);
    }


    public UserDAO getUserDAO() {
        return userDAO;
    }

    public Set<UserDTOImpl> getAllUser() {
        return makeEventDtoSet(userDAO.getAllUser());
    }

    private static Set<UserDTOImpl> makeEventDtoSet(Set<User> users) {
        Set<UserDTOImpl> eventsDto = new HashSet<UserDTOImpl>(0);
        for (User e : users) {
            eventsDto.add(makeUserDto(e));
        }
        return eventsDto;
    }

    public static UserDTOImpl makeUserDto(User user) {
        UserDTOImpl userDto = new UserDTOImpl();
        userDto.setId(user.getId());
        userDto.setName(user.getName());
        userDto.setSurname(user.getSurname());
        userDto.setEmail(user.getEmail());
        userDto.setPatronymic(user.getPatronymic());
        userDto.setPost(user.getPost());
        return userDto;
    }

}

